<template>
  <div class="background">
    <div class="login-box">
      <el-form label-width="80px">
        <h3 style="text-align: center">欢迎登录 文创商城</h3>
        <el-form-item label="帐号">
          <el-input v-model="username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input type="password" v-model="password" @keydown.enter.native="loginClick"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button style="width: 190px" type="primary" @click="loginClick"
            >登录</el-button
          >
          <el-button>注册</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "Login",
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    loginClick() {
      // console.log(this.username,this.password); // Just test the username & password
      axios
        .post("/v1/login", {
          name: this.username,
          password: this.password,
        })
        .then((res) => {
          if (res.data.code === 1) {
            localStorage.setItem("name", this.username);
            this.$router.push({ path: "/Product" });
          } else {
            alert(res.data.msg);
          }
        });
    },
  },
};
</script>

<style>
.background {
  background: content-box radial-gradient(pink, bisque);
  position: absolute;
  height: 100%;
  width: 100%;
}
.login-box {
  border: 1px solid #dcdfe6;
  width: 350px;
  margin: 200px auto;
  padding: 35px 35px 35px 35px;
  border-radius: 10px;
  box-shadow: 0 0 15px #9093996c;
  background-color: rgba(255, 255, 255, 0.8);
}
</style>
